package neu.edu.vn.appmusic.adapter;

import java.util.ArrayList;

import neu.edu.vn.appmusic.R;
import neu.edu.vn.appmusic.object.Song;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SongAlbumAdapter extends ArrayAdapter {
	private ArrayList<Song> listSong;
	private Context mContext;
	private int layoutId;
	
	
	public SongAlbumAdapter(Context context, int resource, ArrayList<Song> objects) {
		super(context, resource, objects);
		mContext = context;
		layoutId = resource;
		listSong = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if(convertView == null){
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(layoutId, null);
			viewHolder = new ViewHolder();
			viewHolder.tvAlbumNameDetail = (TextView) convertView.findViewById(R.id.tvSongName);
			viewHolder.tvAlbumSinger = (TextView) convertView.findViewById(R.id.tvSongAuthor);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Song song = listSong.get(position);
		if(song != null){
			viewHolder.tvAlbumNameDetail.setText(song.getSongName());
			viewHolder.tvAlbumSinger.setText(song.getAuthor());
		}
		 
		return convertView;
	}
	
	static class ViewHolder{
		TextView tvAlbumNameDetail;
		TextView tvAlbumSinger;
	}
}
